﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Brain.Editor;
using BEPUphysics.BroadPhaseEntries;
using BEPUphysics.Collidables.MobileCollidables;
using BEPUphysics.Entities;

namespace Brain.Bepu
{
    public class PickingManager3D_BEPU : PickingManager3D_PhysicsRayTesting
    {
        public PickingManager3D_BEPU()
        {
        }

        protected override IPickedObject HitPicked(RayTestData data)
        {
            if (data.PhysicObject != null)
            {
                BroadPhaseEntry entry = data.PhysicObject as BroadPhaseEntry;
                // BEPU gives a Broad Phase Entry on the Ray Testing
                if (entry is EntityCollidable)
                {
                    EntityCollidable col = entry as EntityCollidable;
                    Entity en = col.Entity;
                    if (en != null)
                    {
                        if (en.Tag is IPickedObject)
                        {
                            return en.Tag as IPickedObject;
                        }
                    }
                }
            }

            return null;
        }
    }
}
